$(function(){	
	//验证用户名或密码不能为空
	$(".submit_input").click(function(){
		var verificatio1=verification($("#loginName").val(),$("#loginPwd").val());
		if(verificatio1){
			$.ajax({
				url: "/shiro/login?userName="+$("#loginName").val()+"&passWord="+$("#loginPwd").val(),
				type: "post",
				dataType: "json",
				data:{},
				success: function(data){
					if(data.code==1){
						alert("登陆成功");
						location.href="/toPath?path=phone/phone-index";
					}else if(data.code==2){
						alert(data.message);
					}else if(data.code==3){
						alert(data.obj);
					}
				},
				error: function(msg){
					alert("ajax连接异常："+msg);
				}
			});
		}else{
			alert("用户名或密码不能为空");
		}
	})
	//判断登录的用户名是否为空
	function verification(name,pwd){
		if(name=='' || pwd==''){
			return false;
		}else{
			return true;
		}
	}
})

var pwd=0;
var name=0;
var eye = document.getElementById("eye");
var pwd = document.getElementById("loginPwd");
var pwd = document.getElementById("loginPwd");

function showhide(){

	if (pwd.type == "password") {
		pwd.type = "text";
		eye.className='fa fa-eye-slash'
	}else {
		pwd.type = "password";
		eye.className='fa fa-eye'
	}
}

function sign(){
	var name=$("#signName").val();
	var pwd=$("#signPwd").val();
	var realName=$("#signRealName").val();
	if(name==''||pwd==''||realName==''){
		alert("请填写完成在注册")
	}else{
		//注册
		$.ajax({
			url: "/shiro/sign",
			type: "post",
			dataType: "json",
			data:$("#signForm").serialize(),
			success: function(data){
				if(data.code==1){
					alert("注册成功")
					location.href="/"
				}else{
					alert(data.message)
				}
				
			},
			error: function(msg){
				alert("ajax连接异常："+msg);
			}
		});
	}
}
function PasswordComparison(){
	if($("#signPwd").val()==$("#signPwd1").val()){
		pwd=1;
		if(name==1){
			$("#signButton").attr("disabled",false);
		}
		$("#signPwdPanDuan").html(" ")			
	}else{
		$("#signPwdPanDuan").html("密码不一致")
		$("#signButton").attr("disabled",true);
		pwd=0;
	}
}
function signNameComparison(){
	$.ajax({
		url: "/shiro/signNameComparison?userName="+$("#signName").val(),
		type: "post",
		dataType: "json",
		data:{},
		success: function(data){
			if(data.code==1){
				name=1;
				if(pwd==1){
					$("#signButton").attr("disabled",false);
				}
				$("#signNamePanDuan").html(" ")
			}else {
				name=0;
				$("#signNamePanDuan").html("用户已存在")
				$("#signButton").attr("disabled",true);
			}
		},
		error: function(msg){
			alert("ajax连接异常："+msg);
		}
	});
}

function toSign(){
	location.href="/toSign"
}
